package com.woniuxy.web.back;

import com.woniuxy.entity.Manager;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.ManagerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Slf4j
@Controller
@RequestMapping("admin/manager")
/**
 * ManagerController
 *
 * @author wmy
 */
@CrossOrigin(value="http://192.168.6.186:8080",allowCredentials = "true")
public class ManagerController {
    @Autowired
    private ManagerService managerService;

    /**
     * 跳转后台登录页面
     * @return
     */
    @GetMapping("login")
    public String toLogin(){

        return "admin/login";
    }


    @PostMapping("login")
    @ResponseBody
    public ResponseEntity login(@RequestBody Manager manager, HttpSession session){
        Manager m=managerService.getByManagerAccount(manager.getAccount());
        if(m == null){
            return new ResponseEntity(404,"No Account");
        }else{
            if (!m.getPassword().equals(manager.getPassword())){
                return new ResponseEntity(405,"Incorrent Password");
            }else{
                session.setAttribute("manager",m);
                return ResponseEntity.SUCCESS;
            }
        }
    }

}

